<?php
// 创建server对象，监听服务器的127.0.0.1:9527端口
$serv = new Swoole\Server('127.0.0.1',9527);
$serv->set([
    'worker_num' => 2,
    'max_request' => 1000
]);
// 监听连接事件
$serv->on('Connect', function ($serv, $fd){
    echo "Client:connect. -{$fd}- \n";
});

// 监听接收事件
$serv->on('Receive', function ($serv, $fd, $from_id, $data){
    echo "recive({$fd})data:{$data}";
    $serv->send($fd,"Server Echo({$fd}-{$from_id}):{$data}");
});

$serv->on('Close', function ($serv, $fd){
    echo "cliend({$fd}):Closed\n";
});

$serv->start();